package org.jeie.actions;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.util.Vector;

import org.jeie.main.Action;
import org.jeie.messages.Messages;

public class PencilAction implements Action {
	public Color c;
	public Vector<Point> p;
	public int size;

	public PencilAction(Vector<Point> p, Color c, int size) { // TODO make
																// better
		this.c = c;
		this.p = p;
		this.size = size;
	}

	public BufferedImage apply(BufferedImage renderedImage) {
		Graphics2D g = renderedImage.createGraphics();
		g.setStroke(new BasicStroke(size, BasicStroke.CAP_ROUND,
				BasicStroke.JOIN_ROUND));
		g.setColor(c);
		for (int i = 0; i < p.size(); i++) {
			if (p.size() == 1) {
				g.fillRect(p.get(0).x, p.get(0).y, 1, 1);
			}
			if (i != p.size() - 1) {
				g.drawLine(p.get(i).x, p.get(i).y, p.get(i + 1).x,
						p.get(i + 1).y);
			}
		}
		g.dispose();
		return renderedImage;
	}

	@Override
	public String getName() {
		return Messages.getString("Action.Pencil"); //$NON-NLS-1$
	}
}
